import Vue from 'vue'
import App from './App.vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    goodList: [
      {
        name: "诸葛亮",
        price: 1000,
        num: 1,
        checked: true,
      },
      {
        name: "蔡文姬",
        price: 1500,
        num: 1,
        checked: false,
      },
      {
        name: "妲己",
        price: 2000,
        num: 1,
        checked: false,
      },
      {
        name: "鲁班",
        price: 2200,
        num: 1,
        checked: false,
      },
    ],
    name: "",
    num: "",
    price: "",
  },
  mutations: {
    statusFn(state, params) {
      // console.log(i, cdS);

      state.goodList[params.index].checked = params.checked
    },
    //大复选框影响小复选框
    isAllBig(state, val) {
      state.goodList.forEach(item => {
        return item.checked = val;
      })
    },
    delOption(state, i) {
      state.goodList.splice(i, 1);
    },
    //添加数据
    addOption(state) {
      if (state.name.trim().length === 0 || state.price.trim().length === 0 || state.num.trim().length === 0) {
        alert('请输入完整信息哦')
        return
      }
      const obj = {
        name: state.name,
        price: state.price,
        num: state.num,
        checked: false
      }
      state.goodList.push(obj);
      state.name = ''
      state.price = ''
      state.num = ''
    }
  },

})

Vue.config.productionTip = false

new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
